package com.lp.chapter001.convert;


import cn.hutool.core.convert.Convert;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.lp.chapter001.enums.SexEnum;

/**
 * easyExcel性别类型转换类
 * @author LP to 2024/03/30
 */
public class EasyExcelSexConvert implements Converter<String> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return null;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    /**
     * 将 Excel 读取到的值转化为 Java 类型
     * @author LP to 2024/3/30
     */
    @Override
    public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return SexEnum.resolveToValue(Convert.toStr(cellData));
    }

    /**
     * 将 Java 类型转为 Excel 中填写的值
     * @author LP to 2024/3/30
     */
    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(SexEnum.resolveToName(value));
    }
}
